﻿@using ST = EmoneyWeiXinCommon.StringTools;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@ST.GetStaticFile("Models/css/colorbox.css")" rel="stylesheet" />
<link href="@ST.GetStaticFile("Models/css/tree_themes/SimpleTree.css")" rel="stylesheet" />
<script src="@ST.GetStaticFile("Scripts/SimpleTree.js")"></script>
<script src="@ST.GetStaticFile("Scripts/jquery.colorbox.js")"></script>
<div class="right">
    <input type="text" id="hidid" style="display: none" />

    <h3>自动回复管理</h3>
    <!--manage-->
    <div class="manage">
        <!--manage_top-->
        <div class="manage_top">
            <ul class="manage_top_ul">
            </ul>
            <ul class="manage_top_ul33 manage_top_ul03">
                <li repid="1" class="manage_top_A"><a>关注语</a></li>
                <li repid="2"><a>无消息自动回复</a></li>
            </ul>
        </div>
        <!--manage_top end-->
        <p class="manage_line"></p>
        <!--manage_top-->
        <div class="manage_top">
            <div class="manage_register">
                <div class="manage_register_p03">
                    <p>
                        <span><i class="icon iconfont">&#xe602;</i>文本模式</span>
                        <span class="gray" id="divtwxx"><i class="icon iconfont">&#xe603;</i>图文模式</span>
                        <span></span>
                    </p>
                    <textarea class="manage_register_mass" id="txtContent"></textarea>
                </div>
            </div>

            <div class="manage_bottom">
                <table border="0" cellpadding="0" cellspacing="0" width="100%" style="display: none" id="tableNewsReport">
                    <tr>
                        <th><span>编号</span></th>
                        <th><span>标题</span></th>
                        <th><span>栏目</span></th>
                        <th><span>发布时间</span></th>
                    </tr>
                    <tbody id="reportList">
                    </tbody>
                </table>
            </div>


            <p class="manage_add">
                <a id="btnSave" style='display:@(new EmoneyWeiXin.Controllers.BaseConfigurationController().DisplayOperate(2, 3, ViewBag.leftid))'>保存</a>
                <a id="btnDel" class="manage_add_font" style='display:@(new EmoneyWeiXin.Controllers.BaseConfigurationController().DisplayOperate(4, ViewBag.leftid))'>删除</a>
            </p>
        </div>
        <!--manage_top end-->
    </div>
    <!--manage end-->
</div>

<script type="text/javascript">
    var weixinid = "";
    var hisid = "1";
    var newsid = "";
    $(document).ready(function () {
        createMemu();
        $("#btnSave").click(function () {
            if (ischeck()) {
                var id = $("#hidid").val();
                var content = $("#txtContent").val();
                if (id > 0) {
                    operate(2, id, content, newsid);
                }
                else {
                    operate(1, 0, content, newsid);
                }
            }
        });
        $("#btnCancel").click(function () {
            reseting();
        });
        $("#btnDel").click(function () {
            var id = $("#hidid").val();
            var content = $("#txtContent").val();
            operate(-1, id, content, newsid);
        });


    });
    function getContentMemu() {
        $(".manage_top_ul .manage_top_A").each(function () {
            weixinid = $(this).attr("typeid");
        })
        if (weixinid > 0) {
            //gotoPage();
            getContentMemu2();
        }
    }

    function getContentMemu2() {
        $(".manage_top_ul33 .manage_top_A").each(function () {
            hisid = $(this).attr("repid");
        })
        if (hisid > 0) {
            gotoPage();
            $('#divtwxx').colorbox({ href: "@ST.GetTrendsFile("Report/NewsReportListSelected")?weixinid=" + weixinid, title: false, iframe: true, width: "95%", height: "95%" });

        }
    }


    //创建labs
    function createMemu() {
        $.ajax({
            type: "get",
            url: "@ST.GetTrendsFile("BaseConfiguration/WeixinUserMemu")" + "?random=" + Math.random(),
            async: true,
            data: { weixinid: "@ViewBag.weixinid" },
            dataType: "html",
            success: function (result) {
                $(".manage_top_ul").html(result);
                $(".manage_top_ul li").click(function () {
                    $(".manage_top_ul li").removeClass("manage_top_A");
                    $(this).addClass("manage_top_A");
                    reseting();
                    getContentMemu();
                });
                //选择关注语或者自动回复项目
                $(".manage_top_ul33 li").click(function () {
                    $(".manage_top_ul33 li").removeClass("manage_top_A");
                    $(this).addClass("manage_top_A");
                    reseting();
                    getContentMemu2();
                });
                getContentMemu();
            }
        });
    }
    function gotoPage() {
        $.ajax({
            type: "post",
            url: "@ST.GetTrendsFile("ReplyManager/GetReplyManager")" + "?random=" + Math.random(),
            async: true,
            data: { weixinid: weixinid, hisid: hisid },
            dataType: "json",
            success: function (result) {
                if (result) {
                    // var dd = result.split('~');
                    // var d1 = dd[0];
                    var d1 = result.obj1;
                    $("#hidid").val(d1["id"]);
                    $("#txtContent").val(d1["CONTENT"]);


                    //显示图文列表
                    var d2 = result.obj2;
                    $("#reportList").html("");
                    $("#tableNewsReport").css("display", "none");
                    if (d2 != null && d2 != undefined && d2 != "" && d2.length > 0) {
                        $("#tableNewsReport").css("display", "");
                        getTWList(d2);
                    }
                }

            }
        });
    }
    function ischeck() {
        var content = $("#txtContent").val();
        if (content == ""&&newsid=="") {
            alert("内容不能为空！");
            $("#txtContent").focus();
            return false;
        }
        return true;
    }

    //编辑操作
    function operate(op, id, content, newsreportids) {
        $.ajax({
            url: "@ST.GetTrendsFile("ReplyManager/UpdateReplyManager")",
                type: "POST",
                async: true,
                data: { op: op, id: id, hisid: hisid, content: content, weixinid: weixinid, newsreportids: newsreportids },
                beforeSend: function () {
                    //showLoading();
                },
                complete: function () {
                    // hiddenLoading();
                },
                success: function (data) {
                    if (data == "1") {
                        gotoPage();
                        reseting();
                        alert("操作成功!");

                    } else alert(data);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    //alert(errorThrown);
                }
            });
        }

        //重置
        function reseting() {
            $("#txtContent").val("");
            $("#hidid").val("0");
            $("#tableNewsReport").css("display", "none");
            $("#reportList").html("");
            newsid = "";
        }


        function getTxtTd(s) {
            return '<td><span>' + s + '</span></td>';
        }
        //查询图文资讯列表
        function getTWList(d) {
            var ids = "";
            var html = "";
            for (var i = 0; i < d.length; i++) {
                html += "<tr>";
                html += getTxtTd(d[i]["ID"]) + getTxtTd(d[i]["title"]) + getTxtTd(d[i]["menuname"]);
                html += getTxtTd(getFormatDate(new Date(d[i]["updatetime"]), "yyyy-mm-dd", 0));
                html += '</tr>';
                ids += d[i]["ID"] + '^';
            }
            newsid = ids.substring(0, ids.length - 1);
            $("#reportList").html(html);
        }
        //显示图文资讯列表
        function getTWList2(newsreportid, titles, menunames, updatetimes) {
            var html = "";
            newsreportid = newsreportid.substring(1, newsreportid.length - 1);
            titles = titles.substring(0, titles.length - 1);
            menunames = menunames.substring(0, menunames.length - 1);
            updatetimes = updatetimes.substring(0, updatetimes.length - 1);
            var arryNewsReportIDs = newsreportid.split('^');
            var arryTitles = titles.split('^');
            var arryMenuNames = menunames.split('^');
            var arryUpdateTimes = updatetimes.split('^');
            for (var i = 0; i < arryNewsReportIDs.length; i++) {
                html += "<tr>";
                html += getTxtTd(arryNewsReportIDs[i]) + getTxtTd(arryTitles[i]) + getTxtTd(arryMenuNames[i]);
                html += getTxtTd(getFormatDate(new Date(arryUpdateTimes[i]), "yyyy-mm-dd", 0));
                html += '</tr>';
            }
            $("#reportList").html(html);
        }

        function UpdatePD(newsreportids, titles, menunames, updatetimes) {
            $('#divtwxx').colorbox.close();
            newsid = newsreportids;
            if (newsid != "") {
                $("#tableNewsReport").css("display", "");
                //显示图文列表
                getTWList2(newsreportids, titles, menunames, updatetimes);
            }
        }

</script>

